package com.xiaolin.basesystem.controller;

import com.xiaolin.basesystem.model.User;
import com.xiaolin.basesystem.utils.OptResult;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/7/18
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    /**
     * 登录
     *
     * @return
     */
    @PostMapping("/login")
    public OptResult login(@RequestBody User user) {
        Map<String, Object> data = new HashMap<>();
        data.put("token", "admin-token");
        return new OptResult(20000, data);
    }

    /**
     * 获取用户信息
     *
     * @param token
     * @return
     */
    @GetMapping("/info")
    public OptResult info(@RequestParam("token") String token) {
        Map<String, Object> data = new HashMap<>();
        data.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        data.put("introduction", "I am a super administrator");
        data.put("name", "Super Admin");
        data.put("roles", Collections.singletonList("admin"));
        return new OptResult(20000, data);
    }

    /**
     * 注销
     *
     * @return
     */
    @PostMapping("/logout")
    public Map<String, Object> logout() {
        Map<String, Object> data = new HashMap<>();
        data.put("code", 20000);
        data.put("data", "success");
        return data;
    }
}
